package src.main.java.org.exception;

import java.util.Scanner;

public class ExceptionTest2 {
    public static void main(String[] args) {
        //调用一个方法，让用户输入一个合适的价格返回为止
        while (true) {
            try {
                System.out.println(getMoney());
            } catch (Exception e) {
                System.out.println("请你输入合法的数字：");
            }
        }
    }
    public static double getMoney(){
        Scanner scanner = new Scanner(System.in);
        while (true){
            System.out.println("请输入您合适的价格：");
            double money = scanner.nextDouble();
            if(money >= 0){
                return money;
            }else{
                System.out.println("您输入的价格是不合适的！");
            }
        }
    }
}
